package promise

//Promise unit test Adapter,exposed promise,resolve,reject
type Adapter struct {
	promise *Promise
}

//create a adapter,and init the promise
func NewAdapter() *Adapter {
	promise := New(func(resolve Resolve, reject Reject) {
		//time.Sleep(time.Millisecond)
		//resolve("success")
	})
	adapter := &Adapter{promise: promise}
	return adapter
}

//export resolve
func (adapter *Adapter) Resolve(value any) {
	adapter.promise.resolve(value)
}

//export reject
func (adapter *Adapter) Reject(err error) {
	adapter.promise.resolve(err)
}

func (adapter *Adapter) Value() any {
	return adapter.promise.value
}
